package com.tangyee.home_exercise_step.bean;

import org.litepal.LitePal;

import java.util.ArrayList;
import java.util.List;

public class HistoryData {

    //日期
    private String date;
    //步数
    private String historyStepNumber;
    //步数对应的距离
    private String distanceText;
    //距离对应的节省的汽油
    private String saveGasoline;
    //步数对应的消耗的卡路里
    private String heatText;
    //卡路里对应的燃烧的脂肪质量
    private String burnFat;
    public List<HistoryData> historyDataList;


    //获取数据库中所有的数据
    public List<HistoryData> getData() {
        List<StepData> stepDataList = LitePal.findAll(StepData.class);
        historyDataList = new ArrayList<>();
        for (StepData stepData : stepDataList) {
            HistoryData historyData = new HistoryData();
            historyData.setHistoryStepNumber(stepData.getStep());
            historyData.setDate(stepData.getToday());
            historyData.setDistanceText();
            historyData.setSaveGasoline();
            historyData.setHeatText();
            historyData.setBurnFat();
            historyDataList.add(historyData);
        }
        return historyDataList;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getHistoryStepNumber() {
        return historyStepNumber;
    }

    public void setHistoryStepNumber(String historyStepnumber) {
        this.historyStepNumber = historyStepnumber;
    }

    public String getDistanceText() {
        return distanceText;
    }

    public void setDistanceText() {
        float distance = (float) (Integer.valueOf(historyStepNumber) * 6.4 / 8000);
        //保留小数点后一位
        java.text.DecimalFormat decimalFormat = new java.text.DecimalFormat("0.0");
        String currentDis = decimalFormat.format(distance);
        this.distanceText = "距离" + currentDis + "公里";
    }

    public String getSaveGasoline() {
        return saveGasoline;
    }

    public void setSaveGasoline() {
        float gasoline = (float) ((Integer.valueOf(historyStepNumber) * 6.4 / 8000) * 0.08);
        //保留小数点后两位位
        java.text.DecimalFormat decimalFormat = new java.text.DecimalFormat("0.00");
        String currentGas = decimalFormat.format(gasoline);
        this.saveGasoline = "相当于节省了" + currentGas + "升汽油";
    }

    public String getHeatText() {
        return heatText;
    }

    public void setHeatText() {
        int heat = Integer.valueOf(historyStepNumber) * 230 / 8000;
        this.heatText = "消耗" + heat + "千卡";
    }

    public String getBurnFat() {
        return burnFat;
    }

    public void setBurnFat() {
        float mburnFat = (float) ((Integer.valueOf(historyStepNumber) * 230 / 8000) * 0.004);
        //保留小数点后两位位
        java.text.DecimalFormat decimalFormat = new java.text.DecimalFormat("0.00");
        String currentBurnFat = decimalFormat.format(mburnFat);
        this.burnFat = "相当于燃烧了" + currentBurnFat + "盎司脂肪";
    }
}
